package com.xgc.book.bookserver.controller;


import com.xgc.book.bookserver.bean.CategoryBean;
import com.xgc.book.bookserver.service.CategoryService;
import com.xgc.book.bookserver.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 分类表 前端控制器
 * </p>
 *
 * @author wrz
 * @since 2023-11-20
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/page")
    public ResultJson getPage(int page, int limit, CategoryBean categoryBean) {
        return categoryService.getPage(page, limit, categoryBean);
    }

    @GetMapping("/info/{categoryId}")
    public ResultJson getInfo(@PathVariable Integer categoryId) {
        return ResultJson.ok(categoryService.getById(categoryId));
    }

    @GetMapping("/select")
    public ResultJson select() {
        return ResultJson.ok(categoryService.list());
    }

    @PostMapping(value = {"/update", "/status"})
    public ResultJson update(@RequestBody CategoryBean categoryBean) {
        categoryService.saveOrUpdate(categoryBean);
        return ResultJson.ok();
    }

    @DeleteMapping("/delete/{categoryId}")
    public ResultJson delete(@PathVariable Integer categoryId) {
        categoryService.delete(categoryId);
        return ResultJson.ok();
    }

}

